/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * frmQuanLyKhachHang.java
 *
 * Created on Aug 22, 2012, 3:05:04 PM
 */
package gui;

import dao.KhachHangDAO;
import dao.LoaiKhachHangDAO;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.TimeZone;
import java.util.Vector;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;
import pojo.Khachhang;
import pojo.Loaikhachhang;

/**
 *
 * @author dtth
 */
public class frmQuanLyKhachHang extends javax.swing.JFrame {

    private List<Loaikhachhang> _llk;
    private List<Khachhang> _lkh;
    private int _iMaKhacHang;
    private int _irow;

    /** Creates new form frmQuanLyKhachHang */
    public frmQuanLyKhachHang() {
        initComponents();

        this._llk = null;
        fillJCbxLoaiKhach();

        this._lkh = KhachHangDAO.layDanhSachKhachHang();
        fillJTable(this._lkh);

        this._irow = 0;
        this._iMaKhacHang = this._lkh.get(0).getMakhachhang();

        Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
        this.jdtcNgaySinh.setCalendar(calendar);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jtfTenKhachHang = new javax.swing.JTextField();
        jrbtnNam = new javax.swing.JRadioButton();
        jrbtnNu = new javax.swing.JRadioButton();
        jdtcNgaySinh = new com.toedter.calendar.JDateChooser();
        jtfDiaChi = new javax.swing.JTextField();
        jtfSoDienThoai = new javax.swing.JTextField();
        jtfEmail = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jcbxLoaiKhachHang = new javax.swing.JComboBox();
        jbtSua = new javax.swing.JButton();
        jbtThem = new javax.swing.JButton();
        jbtXoa = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtbKhachHang = new javax.swing.JTable();
        jbtnDong = new javax.swing.JToggleButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel1.setText("QUẢN LÝ KHÁCH HÀNG");

        jLabel2.setText("Tên Khách Hàng");

        jLabel3.setText("Giới Tính");

        jLabel4.setText("Ngày Sinh");

        jLabel5.setText("Địa Chỉ");

        jLabel6.setText("Số Điện Thoại");

        jLabel7.setText("Email");

        jrbtnNam.setSelected(true);
        jrbtnNam.setText("Nam");
        jrbtnNam.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrbtnNamActionPerformed(evt);
            }
        });

        jrbtnNu.setText("Nữ");
        jrbtnNu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrbtnNuActionPerformed(evt);
            }
        });

        jLabel8.setText("Loại Khách Hàng");

        jcbxLoaiKhachHang.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        jbtSua.setText("Sửa");
        jbtSua.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtSuaActionPerformed(evt);
            }
        });

        jbtThem.setText("Thêm");
        jbtThem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtThemActionPerformed(evt);
            }
        });

        jbtXoa.setText("Xóa");
        jbtXoa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtXoaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(31, 31, 31)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel4)
                            .addComponent(jLabel3))
                        .addGap(19, 19, 19))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel8)
                        .addGap(18, 18, 18)))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jdtcNgaySinh, javax.swing.GroupLayout.DEFAULT_SIZE, 180, Short.MAX_VALUE)
                    .addComponent(jtfTenKhachHang, javax.swing.GroupLayout.DEFAULT_SIZE, 180, Short.MAX_VALUE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jrbtnNam)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jrbtnNu))
                    .addComponent(jcbxLoaiKhachHang, 0, 180, Short.MAX_VALUE))
                .addGap(49, 49, 49)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel6)
                    .addComponent(jLabel5)
                    .addComponent(jLabel7))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jtfEmail, javax.swing.GroupLayout.DEFAULT_SIZE, 187, Short.MAX_VALUE)
                    .addComponent(jtfDiaChi, javax.swing.GroupLayout.DEFAULT_SIZE, 187, Short.MAX_VALUE)
                    .addComponent(jtfSoDienThoai, javax.swing.GroupLayout.DEFAULT_SIZE, 187, Short.MAX_VALUE))
                .addGap(24, 24, 24))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(317, Short.MAX_VALUE)
                .addComponent(jbtThem, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jbtSua, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jbtXoa, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(88, 88, 88))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5)
                            .addComponent(jtfDiaChi, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel6)
                            .addComponent(jtfSoDienThoai, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel7)
                            .addComponent(jtfEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(jtfTenKhachHang, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jrbtnNam)
                            .addComponent(jrbtnNu)
                            .addComponent(jLabel3))
                        .addGap(8, 8, 8)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jdtcNgaySinh, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel4))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jcbxLoaiKhachHang, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel8))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 14, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jbtThem)
                    .addComponent(jbtSua)
                    .addComponent(jbtXoa))
                .addContainerGap())
        );

        jtbKhachHang.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jtbKhachHang.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jtbKhachHangMouseClicked(evt);
            }
        });
        jtbKhachHang.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jtbKhachHangKeyPressed(evt);
            }
        });
        jScrollPane1.setViewportView(jtbKhachHang);

        jbtnDong.setText("Đóng");
        jbtnDong.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnDongActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 652, Short.MAX_VALUE)
                        .addContainerGap())
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jbtnDong, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(44, 44, 44))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(273, 273, 273))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 188, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jbtnDong)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void jbtnDongActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnDongActionPerformed
// TODO add your handling code here:
    //    System.exit(1);
    this.setVisible(false);
}//GEN-LAST:event_jbtnDongActionPerformed

private void jrbtnNamActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrbtnNamActionPerformed
// TODO add your handling code here:
    this.jrbtnNam.setSelected(true);
    this.jrbtnNu.setSelected(false);
}//GEN-LAST:event_jrbtnNamActionPerformed

private void jrbtnNuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrbtnNuActionPerformed
// TODO add your handling code here:
    this.jrbtnNu.setSelected(true);
    this.jrbtnNam.setSelected(false);
}//GEN-LAST:event_jrbtnNuActionPerformed

private void jtbKhachHangKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtbKhachHangKeyPressed
// TODO add your handling code here:
    int key = evt.getKeyCode();
    //JOptionPane.showMessageDialog(this, key, "Thông báo", JOptionPane.INFORMATION_MESSAGE);
    _irow = this.jtbKhachHang.getSelectedRow();
    if (key == 40) {//nhan nut xuong
        _irow++;
    }
    if (key == 38) {//nhan nutlen
        _irow--;
    }

    setValueToControlFromJTable();
}//GEN-LAST:event_jtbKhachHangKeyPressed

private void jtbKhachHangMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jtbKhachHangMouseClicked
// TODO add your handling code here:
    _irow = this.jtbKhachHang.getSelectedRow();

    setValueToControlFromJTable();
}//GEN-LAST:event_jtbKhachHangMouseClicked

private void jbtSuaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtSuaActionPerformed
// TODO add your handling code here:
    Khachhang kh = new Khachhang();
    kh.setMakhachhang(_iMaKhacHang);
    kh.setTenkhachhang(this.jtfTenKhachHang.getText());
    if (this.jrbtnNam.isSelected()) {
        kh.setGioitinh(true);
    } else {
        kh.setGioitinh(false);
    }
    kh.setNgaysinh(this.jdtcNgaySinh.getDate());
    kh.setDiachi(this.jtfDiaChi.getText());
    kh.setSdt(this.jtfSoDienThoai.getText());
    kh.setEmail(this.jtfEmail.getText());
    kh.setLoaikhachhang(this._llk.get(this.jcbxLoaiKhachHang.getSelectedIndex()));

    boolean kq = KhachHangDAO.capnhatThongTinKhachHang(kh);
    if (kq) {
        JOptionPane.showMessageDialog(this, "Sửa thành công !", "Thông báo", JOptionPane.INFORMATION_MESSAGE);
    } else {
        JOptionPane.showMessageDialog(this, "Sửa không được !", "Thông báo", JOptionPane.WARNING_MESSAGE);
    }

    this._lkh = KhachHangDAO.layDanhSachKhachHang();
    fillJTable(this._lkh);
    setValueToControlFromJTable();
}//GEN-LAST:event_jbtSuaActionPerformed

private void jbtThemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtThemActionPerformed
// TODO add your handling code here:
    Khachhang kh = new Khachhang();
    kh.setTenkhachhang(this.jtfTenKhachHang.getText());
    if (this.jrbtnNam.isSelected()) {
        kh.setGioitinh(true);
    } else {
        kh.setGioitinh(false);
    }
    kh.setNgaysinh(this.jdtcNgaySinh.getDate());
    kh.setDiachi(this.jtfDiaChi.getText());
    kh.setSdt(this.jtfSoDienThoai.getText());
    kh.setEmail(this.jtfEmail.getText());
    kh.setLoaikhachhang(this._llk.get(this.jcbxLoaiKhachHang.getSelectedIndex()));

    boolean kq = KhachHangDAO.themKhachHang(kh);
    if (kq) {
        JOptionPane.showMessageDialog(this, "Thêm thành công !", "Thông báo", JOptionPane.INFORMATION_MESSAGE);
    } else {
        JOptionPane.showMessageDialog(this, "Thêm không được !", "Thông báo", JOptionPane.WARNING_MESSAGE);
    }

    this._lkh = KhachHangDAO.layDanhSachKhachHang();
    fillJTable(this._lkh);
    this.jtfTenKhachHang.setText("");
    Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
    this.jdtcNgaySinh.setCalendar(calendar);
    this.jtfDiaChi.setText("");
    this.jtfSoDienThoai.setText("");
    this.jtfEmail.setText("");
}//GEN-LAST:event_jbtThemActionPerformed

private void jbtXoaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtXoaActionPerformed
// TODO add your handling code here:
    Khachhang kh = new Khachhang();
    kh.setMakhachhang(_iMaKhacHang);
    
    boolean kq = KhachHangDAO.xoaKhachHang(kh);
    if (kq) {
        JOptionPane.showMessageDialog(this, "Xóa thành công !", "Thông báo", JOptionPane.INFORMATION_MESSAGE);
    } else {
        JOptionPane.showMessageDialog(this, "Xóa không được !", "Thông báo", JOptionPane.WARNING_MESSAGE);
    }

    this._lkh = KhachHangDAO.layDanhSachKhachHang();
    fillJTable(this._lkh);
    this.jtfTenKhachHang.setText("");
    this.jtfDiaChi.setText("");
    this.jtfSoDienThoai.setText("");
    this.jtfEmail.setText("");
    Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
    this.jdtcNgaySinh.setCalendar(calendar);
}//GEN-LAST:event_jbtXoaActionPerformed

    private void setValueToControlFromJTable() {
        //lây du lieu tai dong dang chon trong table dua vao cac textfield
        this._iMaKhacHang = this._lkh.get(_irow).getMakhachhang();
        this.jtfTenKhachHang.setText(this.jtbKhachHang.getModel().getValueAt(_irow, 0).toString());
        this.jtfDiaChi.setText(this.jtbKhachHang.getModel().getValueAt(_irow, 4).toString());
        this.jtfSoDienThoai.setText(this.jtbKhachHang.getModel().getValueAt(_irow, 5).toString());
        this.jtfEmail.setText(this.jtbKhachHang.getModel().getValueAt(_irow, 6).toString());

        //lay danh muc cua hang vua dc chon trong table vao combpbox Loai Khach Hang
        this.jcbxLoaiKhachHang.setEditable(true);
        this.jcbxLoaiKhachHang.setSelectedItem(this._lkh.get(_irow).getLoaikhachhang().getTenloaikhachhang());
        this.jcbxLoaiKhachHang.setEditable(false);

        if (this.jtbKhachHang.getModel().getValueAt(_irow, 2).toString().equalsIgnoreCase("Nam")) {
            this.jrbtnNam.setSelected(true);
            this.jrbtnNu.setSelected(false);
        } else {
            this.jrbtnNu.setSelected(true);
            this.jrbtnNam.setSelected(false);
        }

        //lay danh muc cua hang vua dc chon trong table vao jCalendar
        String raw = this.jtbKhachHang.getModel().getValueAt(_irow, 3).toString();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        try {
            Date date = format.parse(raw);
            this.jdtcNgaySinh.setDate(date);
        } catch (ParseException ex) {
            // bad date
        }
    }

    private void fillJCbxLoaiKhach() {
        DefaultComboBoxModel cbxModel = new DefaultComboBoxModel();
        this.jcbxLoaiKhachHang.setModel(cbxModel);

        this._llk = LoaiKhachHangDAO.layThongTinLoaiKhachHang();
        for (int i = 0; i < _llk.size(); i++) {
            cbxModel.addElement(_llk.get(i).getTenloaikhachhang());
        }
    }

    private void fillJTable(List<Khachhang> lkh) {
        DefaultTableModel tableModel = new DefaultTableModel();
        tableModel.addColumn("Tên Khách Hàng");
        tableModel.addColumn("Loại Khách");
        tableModel.addColumn("Giới Tính");
        tableModel.addColumn("Ngày Sinh");
        tableModel.addColumn("Địa Chỉ");
        tableModel.addColumn("Điện Thoại");
        tableModel.addColumn("Email");
        this.jtbKhachHang.setModel(tableModel);

        this.jtbKhachHang.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        //gan chieu rong cot TenKhachHang
        this.jtbKhachHang.getColumnModel().getColumn(0).setPreferredWidth(150);
        //gan chieu rong cot Dienthoai
        this.jtbKhachHang.getColumnModel().getColumn(5).setPreferredWidth(100);
        //gan chieu rong cot Email
        this.jtbKhachHang.getColumnModel().getColumn(6).setPreferredWidth(124);

        if (lkh.size() > 0) {
            for (int i = 0; i < lkh.size(); i++) {
                Vector vt = new Vector();
                vt.add(lkh.get(i).getTenkhachhang());
                vt.add(lkh.get(i).getLoaikhachhang().getTenloaikhachhang());
                boolean gioiTinh = lkh.get(i).getGioitinh();
                if (gioiTinh) {
                    vt.add("Nam");
                } else {
                    vt.add("Nữ");
                }
                vt.add(lkh.get(i).getNgaysinh().toString());
                vt.add(lkh.get(i).getDiachi());
                vt.add(lkh.get(i).getSdt());
                vt.add(lkh.get(i).getEmail());

                tableModel.addRow(vt);
            }
        }
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(frmQuanLyKhachHang.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(frmQuanLyKhachHang.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(frmQuanLyKhachHang.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(frmQuanLyKhachHang.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new frmQuanLyKhachHang().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton jbtSua;
    private javax.swing.JButton jbtThem;
    private javax.swing.JButton jbtXoa;
    private javax.swing.JToggleButton jbtnDong;
    private javax.swing.JComboBox jcbxLoaiKhachHang;
    private com.toedter.calendar.JDateChooser jdtcNgaySinh;
    private javax.swing.JRadioButton jrbtnNam;
    private javax.swing.JRadioButton jrbtnNu;
    private javax.swing.JTable jtbKhachHang;
    private javax.swing.JTextField jtfDiaChi;
    private javax.swing.JTextField jtfEmail;
    private javax.swing.JTextField jtfSoDienThoai;
    private javax.swing.JTextField jtfTenKhachHang;
    // End of variables declaration//GEN-END:variables
}
